# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, val=0, left=None, right=None):
#         self.val = val
#         self.left = left
#         self.right = right
class Solution:
    def mergeTrees(self, root1, root2):
        if not root1 and not root2:
            return None
        if not root1:
            return root2
        if not root2:
            return root1
        # 方法一：新建一个节点
        # new_node = TreeNode(root1.val+root2.val)
        # new_node.left = self.mergeTrees(root1.left, root2.left)
        # new_node.right = self.mergeTrees(root1.right, root2.right)
        # return new_node
        
        # 方法二：原地修改（推荐）
        root1.val = root1.val + root2.val
        root1.left = self.mergeTrees(root1.left, root2.left)
        root1.right = self.mergeTrees(root1.right, root2.right)
        return root1